﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ColorDropper : MonoBehaviour
{
    public RectTransform[] colorRects;
    public Color color;
    public HairUnitEmitter emitter;
    void Update()
    {
        bool l, r;
        if (emitter.handMode == HairUnitEmitter.one)
        {
            l = (Input.GetMouseButtonDown(0));
            r = (Input.GetMouseButtonDown(1));
        }
        else
        {
            var ctrl = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
            l = ctrl && Input.GetKeyDown(KeyCode.V);
            r = ctrl && Input.GetKeyDown(KeyCode.C);
        }
        if (!l && !r) return;
        foreach (var rect in colorRects)
        {
            if (RectTransformUtility.RectangleContainsScreenPoint(rect, Input.mousePosition))
            {
                if (l)
                {
                    rect.GetComponentInParent<ColorPickerSlider>().color = color;
                }
                else//r
                {
                    color = rect.GetComponentInParent<ColorPickerSlider>().color;
                }
                return;
            }
        }
    }
}